﻿/*赵贲 2014/8/29备注
 *注意,在ie8的环境下,使用$(doucment).unbind('click'),有可能会把所有基于doucment的事件都清除不仅仅是click,所以务必在unbind时,把方法名传进去
*/

//通用复选框类型(注意区分数据类型：dataTpe=1 ;data[i].Value，data[i].Name ---dataTpe=2,data[i].ItemValue,data[i].ItemText)
function multipleCheckBox(selector, id, data, hideElement, dataType, showValue) {
    dataType == true ? dataType : 1;
    var temwidth = $(selector).width();
    var temstr = "";
    if (dataType == 1) {
        for (var i = 0; i < data.length; i++) {
            if (data[i].ItemStatus == "1") {
                temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].Name + "' value ='" + data[i].Value + "' />" + data[i].Name + "</label></li>";
            }

        }
    } else if (dataType == 2) {
        for (var i = 0; i < data.length; i++) {
            if (data[i].ItemStatus == "1") {
                temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' />" + data[i].ItemText + "</label></li>";
            }
        }
    }

    var divstr = "<div id='" + id + "' class='houseType-keyIds'><ul>" + temstr + "</ul></div>";

    $(selector).after(divstr);

    $(selector).bind("click", function (e) {
        var divpanel = $("#" + id);
        divpanel.show();
        var point = $(this).offset();

        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));
            if ($(selector).val() <= 0 && showValue) {
                $(selector).val(showValue);
            }
        });
        var temfunclick = function (e) {
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    $('#' + hideElement[i]).hide();
                }
            }
            var divpanel = $("#" + id);
            var tempoint = divpanel.offset();
            if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                if (e.target != $(selector)[0]) {
                    divpanel.hide();
                    $(document).unbind("click", temfunclick);
                }
            }
        }
        $(document).unbind("click", temfunclick);
        $(document).bind("click", temfunclick);
    });
}

//房源状态独有方法,设置房源状态，可以设置初始值
function propertyStatusMultipleCheckBox(selector, id, data, hideElement, showValue) {
    var temwidth = $(selector).width();
    var temstr = "";
    var selectorValue = "";
    for (var i = 0; i < data.length; i++) {
        if (data[i].Status == "1") {
            //如果要初始化某个值时的逻辑
           //if (data[i].Category == "1") {
            //    temstr += '<li style="line-height:150%"><label><input style="margin-right:10px;" name="chb' + id + '" type="checkbox" text="' + data[i].Name + '" value ="' + data[i].Value + '" checked="checked"/>' + data[i].Name + '</label></li>';
           //     selectorValue += data[i].Name + ",";
            //} else {
                temstr += '<li style="line-height:150%"><label><input style="margin-right:10px;" name="chb' + id + '" type="checkbox" text="' + data[i].Name + '" value ="' + data[i].Value + '" />' + data[i].Name + '</label></li>';
        }

    }
    $(selector).val(selectorValue.substring(0, selectorValue.length - 1));
    var divstr = "<div id='" + id + "' class='houseType-keyIds'><ul>" + temstr + "</ul></div>";

    $(selector).after(divstr);

    $(selector).bind("click", function (e) {
        var divpanel = $("#" + id);
        divpanel.show();
        var point = $(this).offset();

        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));
            if ($(selector).val() <= 0 && showValue) {
                $(selector).val(showValue);
            }
        });
        var temfunctionclick = function (e) {
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    $('#' + hideElement[i]).hide();
                }
            }
            var divpanel = $("#" + id);
            if (divpanel.length > 0) {
                var tempoint = divpanel.offset();
                if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                    if (e.target != $(selector)[0]) {
                        divpanel.hide();
                        $(document).unbind("click", temfunctionclick);
                    }
                }
            }
        };
        $(document).unbind("click", temfunctionclick);
        $(document).bind("click", temfunctionclick);
    });
}
//房源状态勾选有效

//通用房型类型
function multipleRoomCheckBox(selector, id, data, metaData, hideElement, showValue, showValue2, isUnbindClick) {
    multipleRoomAppendElement(selector, id, data, metaData);
    multipleRoomAppendEvent(selector, id, hideElement, showValue, showValue2, isUnbindClick);
};

function multipleRoomAppendElement(selector, id, data, metaData) {
    var temwidth = $(selector).width();
    var temstr = "";
    if (metaData) {
        var tempData = metaData.split(',');
        var tempResult = '';
        for (var i = 0; i < data.length; i++) {
            var tempNext = true;
            for (var j = 0; j < tempData.length; j++) {
                if (data[i].ItemValue == tempData[j]) {
                    temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' checked=\"checked\" />" + data[i].ItemText + "</label></li>";
                    tempNext = false;
                    tempResult += data[i].ItemText + ',';
                    break;
                }
            }
            if (tempNext) {
                temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' />" + data[i].ItemText + "</label></li>";
            }

        }
        $(selector).val(tempResult.substring(0, tempResult.length - 1));
    } else {
        for (var i = 0; i < data.length; i++) {
            temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' />" + data[i].ItemText + "</label></li>";
        }
    }

    var divstr = "<div class='houseType-keyIds' id='" + id + "'><ul>" + temstr + "</ul></div>";
    //width:" + temwidth + "px
    $('#' + id).empty();
    $(selector).after(divstr);
};

function multipleRoomAppendEvent(selector, id, hideElement, showValue, showValue2, isUnbindClick, verifyFn) {
    $(selector).unbind('click');
    $(selector).bind("click", function (e) {
        var divpanel = $("#" + id);
        if (divpanel.length == 0) {
            return;
        }
        divpanel.show();
        var point = $(this).offset();
        if (isUnbindClick) {
            divpanel.find("input[type='checkbox']").unbind("click");
        }

        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if ($(this).parent().parent().parent().parent().attr('id') == 'propertyType') {
                    if (showValue2) {
                        
                    } else {
                        
                    }

                }
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));
            if ($(selector).val() <= 0 && showValue) {
                $(selector).val(showValue);
            }
        });
        var temfuncclick = function (e) {
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    $('#' + hideElement[i]).hide();
                }
            }
            var divpanel = $("#" + id);
            var tempoint = divpanel.offset();
            if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                if (e.target != $(selector)[0]) {
                    $('#txtHouseTypeKeyIds').blur();
                    divpanel.hide();
                    if (verifyFn) {
                        verifyFn(selector, id);
                    }
                    $(document).unbind("click", temfuncclick);
                }
            }
        }
        $(document).unbind("click",temfuncclick);
        $(document).bind("click", temfuncclick);
    });
};

//房型户型多选
function multipleRoomTypesCheckBox(selector, id, data, hideElement, isSelectedArray, showValue, isUnbindClick) {
    multipleRoomTypesAppendElement(selector, id, data, isSelectedArray);
    multipleRoomTypesAppendEvent(selector, id, hideElement, showValue, isUnbindClick);
};

function multipleRoomTypesAppendElement(selector, id, data, isSelectedArray) {
    var temwidth = $(selector).width();
    var temstr = "";
    if (isSelectedArray) {
        var tempResult = '';
        for (var i = 0; i < data.length; i++) {
            var tempCirculation = true;
            for (var j = 0; j < isSelectedArray.length; j++) {
                if (isSelectedArray[j] == data[i].ItemValue) {
                    temstr += '<li style="line-height:150%"><label><input style="margin-right:10px;" name="chb' + id + '" type="checkbox" text="' + data[i].ItemText + '" value ="' + data[i].ItemValue + '" checked="checked" />' + data[i].ItemText + '</label></li>';
                    tempCirculation = false;
                    tempResult += data[i].ItemText + ',';
                    break;
                }
            }
            if (!tempCirculation) {
                continue;
            }

            temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' />" + data[i].ItemText + "</label></li>";
        }
        $(selector).val(tempResult.substring(0, tempResult.length - 1));
    } else {
        for (var i = 0; i < data.length; i++) {
            temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' />" + data[i].ItemText + "</label></li>";
        }
    }

    var divstr = "<div class='houseType-keyIds' id='" + id + "'><ul>" + temstr + "</ul></div>";
    //width:" + temwidth + "px
    if ($('#' + id).length > 0) {
        $('#' + id + ' ul').html(temstr);

    } else {
        $(selector).after(divstr);
    }
    if ($("#" + id + " ul li").length <= 0) {
        $("#" + id).remove();
    }
};

function multipleRoomTypesAppendEvent(selector, id, hideElement, showValue, isUnbindClick) {
    $(selector).unbind("click");
    $(selector).bind("click", function (e) {
        var divpanel = $("#" + id);
        if (!divpanel) {
            return;
        }
        if (divpanel.length == 0) {
            return;
        }
        divpanel.show();
        var point = $(this).offset();
        if (isUnbindClick) {
            divpanel.find("input[type='checkbox']").unbind("click");
        }

        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));
            if ($(selector).val() <= 0 && showValue) {
                $(selector).val(showValue);
            }
        });
        var temfunclick = function (e) {
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    $('#' + hideElement[i]).hide();
                }
            }
            var divpanel = $("#" + id);
            if (divpanel.length == 0) {
                $(document).unbind("click", temfunclick);
                return;
            }
            var tempoint = divpanel.offset();
            if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                if (e.target != $(selector)[0]) {
                    $('#txtHouseTypeKeyIds').blur();
                    divpanel.hide();
                    $(document).unbind("click", temfunclick);
                }
            }
        }
        $(document).unbind("click", temfunclick);
        $(document).bind("click", temfunclick);
    });
};

//客源新增和编辑的朝向类型
function multipleDirectionCheckBox(selector, id, data, metaData, hideElement, isUnbindClick) {
    multipleDirectionAppendElement(selector, id, data, metaData);
    multipleDirectionAppendEvent(selector, id, hideElement, isUnbindClick);
};

function multipleDirectionAppendElement(selector, id, data, metaData) {
    var temwidth = $(selector).width();
    var temstr = "";
    if (metaData) {
        var tempData = metaData.split(',');
        var tempResult = '';
        for (var i = 0; i < data.length; i++) {
            var tempNext = true;
            for (var j = 0; j < tempData.length; j++) {
                if (data[i].ItemValue == tempData[j]) {
                    temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' checked=\"checked\" />" + data[i].ItemText + "</label></li>";
                    tempNext = false;
                    tempResult += data[i].ItemText + ',';
                    break;
                }
            }
            if (tempNext) {
                temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' />" + data[i].ItemText + "</label></li>";
            }

        }
        $(selector).val(tempResult.substring(0, tempResult.length - 1));
    } else {
        for (var i = 0; i < data.length; i++) {
            temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].ItemText + "' value ='" + data[i].ItemValue + "' />" + data[i].ItemText + "</label></li>";
        }
    }

    var divstr = "<div class='houseType-keyIds' id='" + id + "'><ul>" + temstr + "</ul></div>";
    //width:" + temwidth + "px
    $('#' + id).empty();
    $(selector).after(divstr);
};

function multipleDirectionAppendEvent(selector, id, hideElement, isUnbindClick) {
    $(selector).unbind("click");
    $(selector).bind("click", function (e) {
        var divpanel = $("#" + id);
        divpanel.show();
        var point = $(this).offset();

        if (isUnbindClick) {
            divpanel.find("input[type='checkbox']").unbind("click");
        }
        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if ($(this).parent().parent().parent().parent().attr('id') == 'propertyType') {
                }
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));
            if ($(selector).val() <= 0 && showValue) {
                $(selector).val(showValue);
            }
        });
        var temfunclick = function (e) {
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    $('#' + hideElement[i]).hide();
                }
            }
            var divpanel = $("#" + id);
            var tempoint = divpanel.offset();
            if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                if (e.target != $(selector)[0]) {
                    $('#txtHouseDirectionKeyIds').blur();
                    divpanel.hide();
                    $(document).unbind("click", temfunclick);
                }
            }
        };
        $(document).unbind("click", temfunclick);
        $(document).bind("click", temfunclick);
    });
};

function propertyStatusSelect(selector, data, currentState) {
    $(selector).empty();
    for (var i = 0; i < data.length; i++) {
        if (data[i].Name != currentState) {
            $(selector).append("<option   text='" + data[i].Name + "' value ='" + data[i].Value + "'>" + data[i].Name + "</option>");
        }
    }
}

//城区片区多选
function multipleRegionsCheckBox(selector, id, typeInt, dataArray, hideElement, showValue, metaData, isUnbindClick, districtType, distypeCode) {
    multipleRegionsAppendElement(selector, id, typeInt, dataArray, metaData, districtType, distypeCode);
    multipleRegionsAppendEvent(selector, id, hideElement, showValue, isUnbindClick);
};

function multipleRegionsAppendElement(selector, id, typeInt, dataArray, metaData, districtType, distypeCode) {
    var temwidth = $(selector).width();
    var temstr = "";
    var divstr = '';
    var selectedText = '';
    var tempData = [];
    if (metaData) {
        tempData = metaData.split(',');
    }
    if (dataArray && dataArray != '-1') {
        var selectedKeyIds = [], tempSelected = false;
        $('#' + id).first('ul').find('input[name=chb' + id + ']:checked').each(function () {
            selectedKeyIds.push($(this).attr('value'));
            tempSelected = true;
        });
        if (tempSelected) {
            $(selector).val('片区');
        }
        //片区数据加载 
        for (var j = 0; j < dataArray.length; j++) {
            for (var i = 0; i < Regions.RegionItems.length; i++) {
                if (Regions.RegionItems[i].ParentId == dataArray[j]) {
                    if ($.inArray(Regions.RegionItems[i].Id, selectedKeyIds) != -1 || $.inArray(Regions.RegionItems[i].Id, tempData) != -1) {
                        temstr += '<li style="line-height:150%"><label><input style="margin-right:10px;" name="chb' + id + '" type="checkbox" checked="checked" text="' + Regions.RegionItems[i].Name + '" value ="' + Regions.RegionItems[i].Id + '" parentid="' + Regions.RegionItems[i].ParentId + '" />' + Regions.RegionItems[i].Name + '</label></li>';
                        selectedText += Regions.RegionItems[i].Name + ',';
                    } else {
                        temstr += '<li style="line-height:150%"><label><input style="margin-right:10px;" name="chb' + id + '" type="checkbox" text="' + Regions.RegionItems[i].Name + '" value ="' + Regions.RegionItems[i].Id + '" parentid="' + Regions.RegionItems[i].ParentId + '" />' + Regions.RegionItems[i].Name + '</label></li>';
                    }
                }
            }
        }
        divstr = '<div class="houseType-keyIds" id="' + id + '"><ul>' + temstr + '</ul></div>';

    } else if (dataArray == '-1') {
        //-1是为了给保存条件中点击搜索时能让隐藏div显示

    } else {
        for (var i = 0, l = Regions.RegionItems.length; i < l; i++) {
            if (Regions.RegionItems[i].Level == typeInt) {
                for (var k = 0; k < Regions.RegionItems[i].TypeId.length+1; k++) {
                    //城区类型为null的默认为二手盘  根据ItemNo
                    if (distypeCode == "10") {
                        if (Regions.RegionItems[i].TypeId[k] == districtType || Regions.RegionItems[i].TypeId.length == 0) {
                            //城区
                            if ($.inArray(Regions.RegionItems[i].Id, tempData) != -1) {
                                temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' checked='checked' text='" + Regions.RegionItems[i].Name + "' value ='" + Regions.RegionItems[i].Id + "' />" + Regions.RegionItems[i].Name + "</label></li>";
                                selectedText += Regions.RegionItems[i].Name + ',';
                            } else {
                                temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + Regions.RegionItems[i].Name + "' value ='" + Regions.RegionItems[i].Id + "' />" + Regions.RegionItems[i].Name + "</label></li>";
                            }
                        }
                    } else if (Regions.RegionItems[i].TypeId[k] == districtType) {
                        //城区
                        if ($.inArray(Regions.RegionItems[i].Id, tempData) != -1) {
                            temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' checked='checked' text='" + Regions.RegionItems[i].Name + "' value ='" + Regions.RegionItems[i].Id + "' />" + Regions.RegionItems[i].Name + "</label></li>";
                            selectedText += Regions.RegionItems[i].Name + ',';
                        } else {
                            temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + Regions.RegionItems[i].Name + "' value ='" + Regions.RegionItems[i].Id + "' />" + Regions.RegionItems[i].Name + "</label></li>";
                        }
                    }
                } 
            }
        }
        divstr = "<div class='houseType-keyIds' id='" + id + "'><ul>" + temstr + "</ul></div>";
    }

    if (selectedText) {
        $(selector).val(selectedText.substr(0, selectedText.length - 1));
    }

    //width:" + temwidth + "px
    if ($('#' + id).length > 0) {
        $('#' + id + ' ul').html(temstr);
    } else {
        $(selector).after(divstr);
    }
};

function multipleRegionsAppendEvent(selector, id, hideElement, showValue, isUnbindClick) {
    $(selector).unbind("click");
    $(selector).bind("click", function (e) {
        var divpanel = $("#" + id);
        if (divpanel.find("li").length > 0) {
            divpanel.show();
        }

        var point = $(this).offset();

        if (isUnbindClick) {
            divpanel.find("input[type='checkbox']").unbind("click");
        }
        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));
            if ($(selector).val() <= 0 && showValue) {
                $(selector).val(showValue);
            }
        });
        var temfunctionclick = function (e) {
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    $('#' + hideElement[i]).hide();
                }
            }
            var divpanel = $("#" + id);
            if (divpanel.length > 0) {
                var tempoint = divpanel.offset();
                if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                    if (e.target != $(selector)[0]) {
                        $('#txtHouseTypeKeyIds').blur();
                        divpanel.hide();
                        $(document).unbind("click", temfunctionclick);
                    }
                }
            }
        };
        $(document).unbind("click", temfunctionclick);
        $(document).bind("click", temfunctionclick);
    });
};

//栋座单元多选
function multipleBuildingCheckBox(selector, id, data, hideElement,checkedArray) {
    var temwidth = $(selector).width();
    var temstr = "";
    var divstr = "";
    var selectedText = "";

    if (checkedArray) {
        for (var i = 0, l = data.length; i < l; i++) {
            var isCheckedSelector = false;
            for (var j = 0; j < checkedArray.length; j++) {
                if (checkedArray[j] == data[i].BuildingName) {
                    isCheckedSelector = true;
                    temstr += '<li style="line-height:150%"><label><input style="margin-right:10px;" name="chb' + id + '" type="checkbox" text="' + data[i].BuildingName + '" checked="checked" value="' + data[i].KeyId + '"/>' + data[i].BuildingName + '</label></li>';
                }
            }

            if (!isCheckedSelector) {
                temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].BuildingName + "' value='" + data[i].KeyId + "'/>" + data[i].BuildingName + "</label></li>";
            }
            
        }
    } else {
        for (var i = 0, l = data.length; i < l; i++) {
            temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].BuildingName + "' value='" + data[i].KeyId + "'/>" + data[i].BuildingName + "</label></li>";

        }
    }

    divstr = "<div class='houseType-keyIds' id='" + id + "'><ul>" + temstr + "</ul></div>";

    //width:" + temwidth + "px
    if ($('#' + id).length > 0) {
        $('#' + id + ' ul').html(temstr);
    } else {
        $(selector).after(divstr);
    }
    if (data.length > 0) {
        var divpanel = $("#" + id);
        divpanel.show();
        var point = $(this).offset();

        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));

        });
         temfunctionclick2 = function (e) {
            
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    if (hideElement[i].indexOf(".") != -1) {
                        $(hideElement[i]).css("display", "none");
                    } else {
                        $('#' + hideElement[i]).hide();
                    }

                }
            }
            var divpanel = $("#" + id);
            var tempoint = divpanel.offset();
            if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                if (e.target != $(selector)[0]) {
                    $('#txtHouseTypeKeyIds').blur();
                    divpanel.hide();
                    $(document).unbind("click", temfunctionclick2);
                }
            }
        };
        $(document).unbind("click",temfunctionclick2);
        setTimeout("$(document).bind('click', temfunctionclick2)", 300);
    }
    $(selector).bind("click", function (e) {
        var divpanel = $("#" + id);
        if ($("#" + id + ' ul').html().length > 5) {
            divpanel.show();
        }

        var point = $(this).offset();

        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));

        });
        var temfuncclick = function (e) {
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    if (hideElement[i].indexOf(".") != -1) {
                        $(hideElement[i]).css("display", "none");
                    } else {
                        $('#' + hideElement[i]).hide();
                    }

                }
            }
            var divpanel = $("#" + id);
            var tempoint = divpanel.offset();
            if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                if (e.target != $(selector)[0]) {
                    $('#txtHouseTypeKeyIds').blur();
                    divpanel.hide();
                    $(document).unbind("click", temfuncclick);
                }
            }
        };
        $(document).unbind("click",temfuncclick);
        $(document).bind("click", temfuncclick);
    });
};

//房源搜索栋座单元多选（上面的不要用于房源搜索）
function multipleBuildingCheckBoxByProperty(selector, id, data, hideElement) {
    var temwidth = $(selector).width();
    var temstr = "";
    var divstr = "";
    var selectedText = "";

    for (var i = 0, l = data.length; i < l; i++) {
        temstr += "<li style='line-height:150%'><label><input style='margin-right:10px;' name='chb" + id + "' type='checkbox' text='" + data[i].BuildingName + "' />" + data[i].BuildingName + "</label></li>";

    }
    divstr = "<div class='houseType-keyIds' id='" + id + "'><ul>" + temstr + "</ul></div>";

    //width:" + temwidth + "px
    if ($('#' + id).length > 0) {
        $('#' + id + ' ul').html(temstr);
    } else {
        $(selector).after(divstr);
    }
    if (data.length > 0) {
        var divpanel = $("#" + id);
        divpanel.show();
        var point = $(this).offset();

        divpanel.find("input[type='checkbox']").bind("click", function () {
            var temresult = "";
            divpanel.find("input[type='checkbox']").each(function () {
                if (this.checked) {
                    temresult += this.attributes["text"].value + ",";
                }
            });
            $(selector).val(temresult.substring(0, temresult.length - 1));

        });
        var temfunctionclick = function (e) {
            if (hideElement) {
                for (var i = 0; i < hideElement.length; i++) {
                    if (hideElement[i].indexOf(".") != -1) {
                        $(hideElement[i]).css("display", "none");
                    } else {
                        $('#' + hideElement[i]).hide();
                    }

                }
            }
            var divpanel = $("#" + id);
            var tempoint = divpanel.offset();
            if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
                if (e.target != $(selector)[0]) {
                    $('#txtHouseTypeKeyIds').blur();
                    divpanel.hide();
                    $(document).unbind("click", temfunctionclick);
                }
            }
        };
        $(document).unbind("click", temfunctionclick);
        $(document).bind("click", temfunctionclick);
    }
    //$(selector).bind("click", function (e) {
    //    var divpanel = $("#" + id);
    //    if ($("#" + id + ' ul').html().length > 5) {
    //        divpanel.show();
    //    }

    //    var point = $(this).offset();

    //    divpanel.find("input[type='checkbox']").bind("click", function () {
    //        var temresult = "";
    //        divpanel.find("input[type='checkbox']").each(function () {
    //            if (this.checked) {
    //                temresult += this.attributes["text"].value + ",";
    //            }
    //        });
    //        $(selector).val(temresult.substring(0, temresult.length - 1));

    //    });
    //    var temfuncclick = function (e) {
    //        if (hideElement) {
    //            for (var i = 0; i < hideElement.length; i++) {
    //                if (hideElement[i].indexOf(".") != -1) {
    //                    $(hideElement[i]).css("display", "none");
    //                } else {
    //                    $('#' + hideElement[i]).hide();
    //                }

    //            }
    //        }
    //        var divpanel = $("#" + id);
    //        var tempoint = divpanel.offset();
    //        if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
    //            if (e.target != $(selector)[0]) {
    //                $('#txtHouseTypeKeyIds').blur();
    //                divpanel.hide();
    //                $(document).unbind("click");
    //            }
    //        }
    //    };
    //    $(document).unbind("click", temfuncclick);
    //    $(document).bind("click", temfuncclick);
    //});
};
